import java.util.StringTokenizer;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.smack.util.StringUtils;

public class InputListener implements PacketListener {
	public Input i;
	public boolean ratingCheck = false;
	public boolean out = false;

	public InputListener(Input arg) {
		i = arg;
	}

	public void processPacket(Packet packet) {
		System.out.println("recieving packet: " + packet);
		System.out.println("packet class: " + packet.getClass());

		if (packet.getClass() == Registration.class && ratingCheck == true) {
			i.ratingReset(((Registration) packet).getAttributes());
			ratingCheck = false;
		}
		if (packet.getClass() == Message.class) {
			System.out.println("recieving message");
			Message tmp = ((Message) packet);
			StringTokenizer st = new StringTokenizer(StringUtils
					.parseResource(packet.getFrom()));
			if (StringUtils.parseResource(packet.getFrom()).equals(""))
				;
			else {
				i.processMessage(st.nextToken(), tmp.getBody());
			}
			System.out.println("processed message");
		}
	}
}
